<template>
  <div id="my-aside">
    <el-tabs
      :tab-position="tabPosition"
      :stretch="stretch"
      @tab-click="handleClick"
    >
      <el-tab-pane
        :label="item.title"
        v-for="item in menuList"
        :key="item.title"
      >
        <div class="tab-pane-content">
          <div v-show="IsWheel" class="slot">
            <div :class="['wheel-show', item.wheelNode]">
              <component
                :is="item.wheelNode"
                :show="Isshow"
                @confirm="confirm"
                @close="close"
                :class="{ carousel: item.wheelNode === 'carousel' }"
              >
                <div v-if="item.wheelNodeItem">
                  <component
                    :is="item.wheelNodeItem"
                    v-for="(item1, index) in picList"
                    :imgPath="item1"
                    :key="index"
                  ></component>
                </div>
              </component>
              <div
                class="wheel-button"
                @click="show"
                v-show="item.wheelNode == 'modal'"
              >
                点击显示
              </div>
            </div>
          </div>
          <div>
            <iframe
              style="width: 100%; height: 100%"
              scrolling="no"
              class="iframe"
              :src="item.path"
              frameborder="0"
            ></iframe>
          </div>
        </div>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
// window.onload = () => {
//   if (document.readyState == "complete") {
//     const oIframe = document.querySelector("#bdIframe");
//     if (oIframe) {
//       oIframe.style.height =
//         oIframe.contentWindow.document.body.offsetHeight + "px";
//       console.log(oIframe.contentWindow.document.body.offsetHeight);
//     }
//   }
// };
export default {
  name: "MyAside",
  props: {
    menuList: Array,
    IsWheel: {
      type: Boolean,
    },
  },
  components: {},
  methods: {
    handleClick(tab, event) {
      const oIframe = document.getElementsByClassName("el-tabs__content")[0]
        .children;

      const iframe = oIframe[tab.index].children[0].children[1].children[0];
      this.$nextTick(function () {
        console.log(iframe.contentWindow.document.body.offsetHeight);
        iframe.style.height =
          iframe.contentWindow.document.body.offsetHeight + "px";
      });
    },
    //模态框
    show() {
      this.Isshow = true;
    },
    confirm() {
      this.Isshow = false;
    },
    close() {
      this.Isshow = false;
    },
  },
  data() {
    return {
      tabPosition: "left",
      stretch: true,
      Isshow: false,
      //轮播图
      picList: [
        "https://gitee.com/ray254258/picture-store/raw/master/carousel.jpg",
        "https://gitee.com/ray254258/picture-store/raw/master/carousel1.jpg",
        "https://gitee.com/ray254258/picture-store/raw/master/carousel2.jpg",
      ],
    };
  },
  mounted() {
    const oIframe = document.getElementsByClassName("el-tabs__content")[0]
      .children;
    //该处dom操作的耦合性较高，待优化
    const iframe = oIframe[0].children[0].children[1].children[0];
    this.$nextTick(function () {
      iframe.contentWindow.window.onload = () => {
        if (iframe.contentWindow.document.readyState == "complete") {
          iframe.style.height =
            iframe.contentWindow.document.body.offsetHeight + "px";
        }
      };
    });
  },
};
</script>

<style scoped>
.wheel-show {
  position: initial;
  overflow: initial;
  background-color: #ffffff;
  padding: 20px;
}
.wheel-button {
  border-radius: 5px;
  background-color: rgb(244, 126, 96, 0.2);
  display: inline-block;
  color: #888;
  padding: 10px;
}
.wheel-button:hover {
  color: #fff;
}
.carousel {
  width: 96%;
  height: 300px;
}
</style>